import React from 'react';
import { Empty } from 'antd';
import ReactEcharts from '@/components/Echarts';

const getOption = (data = []) => ({
    tooltip: {
        trigger: 'item'
    },
    legend: {
        type: 'scroll',
        x: 'center',
        data: data.map(item => item.name)
    },
    grid: {
        left: '5%'
    },
    xAxis: {
        show: false,
        type: 'category',
        data: ['数量']
    },
    yAxis: {
        type: 'value',
        splitLine: {
            lineStyle: {
                type: 'dashed'
            }
        },
        axisLabel: {
            color: 'rgba(0,0,0,0.45)'
        },
        axisLine: {
            show: false,
            lineStyle: {
                type: 'dashed'
            }
        },
        axisTick: {
            show: false
        },
        minInterval: 1
    },
    series: data.map(item => ({
        data: [item.value],
        name: item.name,
        type: 'bar'
    }))
});
const Ygjsfb = ({ data }) => {
    if (!data || data.length === 0) {
        return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />;
    }
    return <ReactEcharts option={getOption(data)} />;
};

export default Ygjsfb;
